package com.albert.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static com.albert.thread.ThreadPool.service;

public class TwoTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //两个都完成
        CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("开始线程一的信息"+Thread.currentThread());
            System.out.println("输出结果1");
            return 10 / 4;
        }, service);
        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("开始线程2的信息:"+Thread.currentThread());
            System.out.println("输出结果2");
            return "hello";
        }, service);

        //不需要二者结果
        future1.runAfterBothAsync(future2,()->{
            System.out.println("任务三开始");
        },service);

        //获取俩结果无返回值
        future1.thenAcceptBothAsync(future2,(f1,f2)->{
            System.out.println("任务三开始"+f1+"->"+f2);
        },service);

        CompletableFuture<String> future3 = future1.thenCombineAsync(future2, (f1, f2) -> {
            System.out.println("任务三开始");
            return "over";
        }, service);
        System.out.println(future3.get());
    }
}
